function fn1(a, b) {
  console.log('this-', this)
  console.log(a, b);
  return 'this is fn1';
}

// const fn2 = fn1.bind({ x: 100 }, 10, 20, 30);
// const res = fn2();
// console.log(res);

// 模拟bind
Function.prototype.bindSelf = function() {
  // 将参数拆解为数组
  const args = Array.prototype.slice.call(arguments)
  // 获取 this (数组第一项)
  const t = args.shift()
  // fn1.bind(...) 中的 fn1
  const self = this
  console.log(self)
  // 返回一个函数
  return function() {
    return self.apply(t, args)
  }
}

Function.prototype.bindSelf2 = function(context, ...args) {
  return (...rest) => this.call(context, ...args, ...rest);
}

// const fn2 = fn1.bindSelf2({ x: 100 }, 10, 20, 30);
// const res = fn2();
// console.log(res);

var a = 10
const obj = {
  a: 20,
  fn() {
    setTimeout(function() {
      console.log(this)
    })
  }
}
obj.fn()